import { create, StateCreator } from 'zustand'
import { devtools, persist } from 'zustand/middleware'

// 创建基础存储的辅助函数
export const createStore = <T>(
  initialState: T,
  storeCreator: StateCreator<T, [], []>
) => create<T>()(devtools(storeCreator))

// 创建持久化存储的辅助函数
export const createPersistStore = <T>(
  name: string,
  initialState: T,
  storeCreator: StateCreator<T, [], []>
) => create<T>()(
  devtools(
    persist(storeCreator, {
      name: `novelai-${name}`
    })
  )
)

// 常用的状态类型
export interface BaseState {
  isLoading: boolean;
  error: string | null;
}

// 重置状态的辅助函数
export const resetState = <T>(initialState: T) => (state: T): T => ({
  ...initialState
}) 